<?php

include_once "db.php";

include_once "chapter.php";

class Region
{
    private $region_id;
    private $region_name;
    private $chapters;

    private $regionfound;

    public function __construct($id)
    {
        global $mysqli;
        $query = "SELECT * FROM Regions WHERE RegionID = '" . $id . "'";
        $data = $mysqli->query($query);
        if ($data->num_rows != 0)
        {
            $row = $data->fetch_array(MYSQLI_ASSOC);
            $this->region_id = intval($row["RegionId"]);
            $this->region_name = $row["RegionName"];
            $chapters = array();
            $query = "SELECT * FROM Chapters WHERE RegionID = '" . $this->region_id . "'";
            $data = $mysqli->query($query);
            if (!empty($data))
            {
                while ($row = $data->fetch_array())
                {
                    $chapter_object = new Chapter($row["ChapterId"]);
                    array_push($chapters, $chapter_object);
                }
                $this->regionfound = true;
            } else
            {
                $this->regionfound = false;
            }
        } else
        {
            $this->regionfound = false;
        }
    }

    public function getRegionId()
    {
        return $this->region_id;
    }

    public function getRegionName()
    {
        return $this->region_name;
    }

    public function getChapters()
    {
        return $this->chapters;
    }

    public function regionFound()
    {
        return $this->regionfound;
    }
}

?>